<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px">
      <!-- 查询区域 -->
      <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="onQuery">
        <a-row>
          <a-col :span="6">
            <a-form-model-item label="计划名称">
              <a-input v-model="queryParam.planName" placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="考核对象">
              <a-input v-model="queryParam.assessUser" placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="总得分">
              <a-input v-model="queryParam.assessProposal" placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :span="4">
            <a-form-model-item :wrapper-col="{ offset: 0 }" style="margin-bottom: 0">
              <a-button type="primary" @click="onQuery"> 查询 </a-button>
              <a-button style="margin-left: 10px" @click="onResetForm"> 重置 </a-button>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>
    <a-card>
      <div class="table-page-content">
        <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
                 :columns="!isFromSelf ? columns.filter((item) => item.dataIndex !== 'selfScope') : columns.filter((item) => item.dataIndex !== 'assessScore' && item.dataIndex !== 'assessProposal')" :dataSource="pageData" @selectedRow="onSelectedRow" @change="onTableChange">
        </z-table>
      </div>
    </a-card>
  </div>

</template>

<script>
  import { getDictItemsFromCache } from '@/api/api'
  import Api from '@/api/sjsk/performanceServiceQuery'

  export default {
    name: "selfExamine",
    components: {
    },
    data() {
      return {
        labelCol: { span: 6 },
        wrapperCol: { span: 17 },
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: 'order',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          },
          {
            title: '指标名称',
            align: "center",
            dataIndex: 'indicatorName'
          },
          {
            title: '指标类型',
            align: "center",
            dataIndex: 'indicatorType',
          },
          {
            title: '基数',
            align: "center",
            dataIndex: 'cardinalNumber'
          },
          {
            title: '任务量',
            align: "center",
            dataIndex: 'taskNumber'
          },
          {
            title: '完成量',
            align: 'center',
            dataIndex: 'finishNumber'
          },
          {
            title: '加/减分基数',
            align: 'center',
            dataIndex: 'addCardinalNumber'
          },
          {
            title: '上限分值',
            align: 'center',
            dataIndex: 'upperScore'
          },
          {
            title: '下限分值',
            align: 'center',
            dataIndex: 'lowerScore'
          },
          {
            title: '权重(%)',
            align: 'center',
            dataIndex: 'weight'
          },
          {
            title: '是否可修正得分',
            align: 'center',
            dataIndex: 'isScoreCorrection'
          },
          {
            title: '是否与上级共享评分',
            align: 'center',
            dataIndex: 'isSharedScore'
          },
          {
            title: '是否禁用',
            align: 'center',
            dataIndex: 'isDisable'
          },
          {
            title: '自评得分',
            align: 'center',
            dataIndex: 'selfScope',
          }, //自评明细有的字段
          {
            title: '考核得分',
            align: 'center',
            dataIndex: 'assessScore',
          }, //执行考核明细有的字段
          {
            title: '考核意见',
            align: 'center',
            dataIndex: 'assessProposal',
          }, //执行考核明细有的字段
        ],
        typeArr: getDictItemsFromCache('personType'),
        loading: false,
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
        },
        queryParam:{},
        pageData: {},
        isFromSelf:true,
        checkList:[],
      }
    },
    created(){
      if(this.$route.query.type === 'executeExamine'){
        this.isFromSelf= false
      }
      this.onQuery()
    },
    methods: {
      // 查询
      onQuery() {
        this.pageFilter.pageNo = 1
        this.refreshTable()
      },
      // 重置
      onResetForm() {
        this.queryParam = {}
        this.pageFilter = {
          pageNo: 1,
          pageSize: 10
        }
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.checkList = keys;
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = { currentPage: 'pageNo' }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      refreshTable() {
        this.loading = true
        this.queryParam.id = this.$route.query.id;
        let params = Object.assign({}, this.queryParam, this.pageFilter)
        let interfaceMethod = null;
        if(this.$route.query.type === 'executeExamine'){
          interfaceMethod = Api.selfEvaluationDetailNicety(params)
        }else{
          interfaceMethod = Api.getSelfEvaluationList(params)
        }
        interfaceMethod.then((res) => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
            this.$refs.table.onClearRowKeys()
          } else {
            this.loading = false
            this.pageData = {}
            this.$message.warn('请求失败！')
          }
        }).catch((e) => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
      }
    }
  }
</script>
<style lang="less" scoped>

</style>